<%@page import="org.prs.persistence.MedicalDatabasePersistence"%>
<%@page import="org.prs.model.Medical"%>
<%@page import="org.prs.persistence.RelationshipTypeDatabasePersitence"%>
<%@page import="org.prs.model.Guardian"%>
<%@page import="org.prs.persistence.GuardianDatabasePersistence"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="org.prs.model.SchoolStage"%>
<%@page import="org.prs.persistence.SchoolStageDatabasePersistence"%>
<%@page import="com.prs.util.NameUtil"%>
<%@page import="com.prs.util.FileUtil"%>
<%@page import="org.prs.model.Photo"%>
<%@page import="org.prs.persistence.PhotoDatabasePersitenceManager"%>
<%@page import="org.prs.persistence.ChildDatabasePersitenceManager"%>
<%@page import="org.prs.model.Child"%>
<%@page import="org.prs.model.User"%>
<%@page import="org.apache.commons.validator.GenericValidator"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@page contentType="text/html"  language="java" %>
<%
    User loggedInUser = (User) session.getAttribute("loggedinuser");

    if (loggedInUser == null) {
        session.setAttribute("loginmsg", "<div id='loginmsg'>Please log in to use services</div>");
        response.sendRedirect("index.jsp");
    }
    int childId = 0;
    Child child = new Child();
    ChildDatabasePersitenceManager persistChild = new ChildDatabasePersitenceManager();
    PhotoDatabasePersitenceManager persistPhoto = new PhotoDatabasePersitenceManager();
    SchoolStageDatabasePersistence persistSchoolStage = new SchoolStageDatabasePersistence();
    SchoolStage schoolStage = new SchoolStage();
    List<Medical> healths = new ArrayList<Medical>();
    MedicalDatabasePersistence persistHealth = new MedicalDatabasePersistence();
    GuardianDatabasePersistence persistGuardian = new GuardianDatabasePersistence();
    List<Guardian> guardians = new ArrayList<Guardian>();
    RelationshipTypeDatabasePersitence persistRelationshipType = new RelationshipTypeDatabasePersitence();
    List<Photo> photos = new ArrayList<Photo>();
    try {
        childId = Integer.parseInt(request.getParameter("childid"));
        child = persistChild.getChildById(childId);
        schoolStage = persistSchoolStage.getSchoolStageById(child.getSchoolStageId());
        guardians = persistGuardian.getChildGuardians(child.getChildId());
        healths = persistHealth.getChildHealthAssessment(child.getChildId());
        photos = persistPhoto.getChildPhotos(child.getChildId());
        request.setAttribute("child", child);
        request.setAttribute("school", schoolStage);
        request.setAttribute("photos", photos);
        request.setAttribute("guardians", guardians);
        request.setAttribute("healths", healths);
        session.setAttribute("currentchildid", childId);

    } catch (NumberFormatException e) {
        response.sendRedirect("listChildren.jsp");
    }

%>
<html xmlns="http://www.w3.org/1999/xhtml">

    <head>
        <title>Patnership Registration System | New Child</title>
        <link rel="SHORTCUT ICON" href="images/favicon.ico" />
        <link href="style.css" rel="stylesheet" type="text/css" media="screen" />
        <script type="text/javascript" src="js/menu.js" language="JavaScript">
        </script>
        <script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
        <script type="text/javascript" src="js/jquery-ui-1.8.10.custom.min.js"></script>
        <link rel="stylesheet" href="css/jquery/jquery-ui-1.8.10.custom.css" type="text/css" />

        <link rel="stylesheet" href="imagedisplay.css" type="text/css"/>
        <script type="text/javascript" src="imagesdisplay.js"></script>
        <script type="text/javascript" src="js/child.js"></script>

        <script type="text/javascript">
            $(function() {
                $( ".datefield" ).datepicker({
                    changeMonth: true,
                    changeYear: true
                });
            });


        </script>
    </head>
    <body>
        <div id="wrapper">
            <div id="header">
                <div id="logo">
                    <h1><a href="#">Patnership Record System </a></h1>
                </div>
                <div id="menu">
                    <jsp:include page="includes/header.jsp"></jsp:include>
                </div>
            </div>
            <!-- end #header -->
            <div id="page">
                <div id="page-bgtop">
                    <div id="page-bgbtm">
                        <div id="content">
                            <div id ="childname"><label>${child.firstName} ${child.middleName} ${child.lastName}</label></div>

                            <div id="childimages">
                                <label> ${child.firstName} Images</label>


                                <div id="slideshow">
                                    <span class="control" id="leftControl">

                                    </span>
                                    <div id="slidesContainer">
                                        <div id="slideInner">
                                            <c:forEach var="photo" items="${photos}">
                                                <div class="slide">

                                                    <div class="slideimage">
                                                        <img src="${photo.path}" alt="test" />
                                                    </div>
                                                    <div class="slidecaption">

                                                        <div class="captionheading">Image:    </div>
                                                        <div class="captiontext">${photo.name}</div>


                                                    </div>
                                                </div>  
                                            </c:forEach>
                                        </div>



                                    </div>
                                    <span style="display: none;" class="control" id="rightControl">                                   
                                    </span>








                                </div>

                                <a href="addPhoto.jsp" class="childlink">Add Photo</a>
                            </div>
                            <div id="childbio" >
                                <table width="100%">
                                    <tr>
                                        <td><label>Age</label></td>
                                        <td>${child.dateOfBirth}</td>
                                    </tr>
                                    <tr>
                                        <td><label>Gender</label></td>
                                        <td>${child.gender}</td>
                                    </tr>

                                </table>
                            </div>
                            <div id="education" >
                                <table width="100%">
                                    <tr>
                                        <td><label>School Stage</label></td>
                                        <td>${school.name}</td>
                                    </tr>
                                    <tr>
                                        <td><label>School</label></td>
                                        <td>${school.name}</td>
                                    </tr>

                                </table>
                            </div>
                            <div id="health" >
                                <table width="100%">
                                    <tr>
                                        <td colspan="2"><label>Health Details</label></td>
                                    </tr>
                                    <tr>
                                        <td><label>Date</label></td>
                                        <td><label>Hospital</label></td>
                                         <td><label>Ailment</label></td>
                                          <td><label>Cost</label></td> 
                                          
                                    </tr>
                                    <c:forEach var="health" items="${healths}">
                                        <tr>
                                            <td>
                                                ${health.dateOfAssessment}
                                            </td>
                                            <td>
                                                ${health.hospitalVisited}
                                            </td>
                                             <td>
                                                ${health.ailment}
                                            </td>
                                             <td>
                                                ${health.cost}
                                            </td>
                                        </tr>
                                    </c:forEach>
                                        <tr>
                                            <td>
                                                <a href="#" onclick="addMedicalInformation()">Add Medical Information</a>
                                                <div id="addmedicalinformation">Show</div>
                                            </td>
                                        </tr>
                                </table>
                            </div>
                            <div id="relations" >
                                <table width="100%" id="relationstable">
                                    <tr>
                                        <td colspan="3"><label>Relations</label></td>
                                    </tr>
                                    <tr>
                                        <td><label>Name</label></td>
                                        <td><label>Relationship</label></td>
                                        <td><label>Phone Number</label></td>
                                    </tr>
                                    <c:forEach var="guardian" items="${guardians}">
                                        <tr>
                                            <td>
                                                <div id="name${guardian.guardianId}">
                                                    ${guardian.lastName} ${guardian.firstName} ${guardian.middleName}
                                                    <a href="#" onclick="editGuardianName('${guardian.guardianId}')">Edit Name</a>
                                                </div>
                                                <div id="editnameerror"></div>
                                            </td>
                                            <td>${guardian.relationshipTypeId}</td>
                                            <td>${guardian.phoneNumber}</td>
                                        </tr>
                                        <input type='hidden' id='guardianfname${guardian.guardianId}' value='${guardian.firstName}'/>
                                        <input type='hidden'  id='guardianlname${guardian.guardianId}' value='${guardian.lastName}'/>
                                        <input type='hidden' id='guardianmname${guardian.guardianId}' value='${guardian.middleName}'/>
                                    </c:forEach>
                                    <tr>
                                        <td><div id="addguardian"></div></td>
                                        <td><a href="#" onclick="addGuardian()">Add Guardian</a></td>
                                    </tr>
                                    <div id="newrows"></div>
                                </table>
                                <input type="hidden" id="childid" value="${child.childId}"/>
                            </div>
                        </div>
                        <!-- end #content -->
                        <div id="sidebar">

                            <jsp:include page="includes/userProfile.jsp"></jsp:include>


                        </div>
                        <!-- end #sidebar -->
                        <div style="clear: both;">&nbsp;</div>
                    </div>
                </div>
            </div>
            <!-- end #page -->
        </div>
        <jsp:include page="includes/footer.jsp"></jsp:include>
    </body>
</html>
